<style lang="scss" scoped>
	.content {

		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.nav {
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		padding-bottom: 10rpx;
		border-bottom: 1px solid #dee2ee;
		background-color: white;
		z-index: 999;
	}

	.top {
		padding: 20rpx 30rpx;
	}

	.search {
		width: 554rpx;
		height: 76rpx;
		background: #f4f5f7;
		border: 2rpx solid #f5f5f5;
		border-radius: 46rpx;
		padding: 20rpx;

		.ipt {
			flex: 1;
		}
	}


	.lists {
		margin-bottom: 50rpx;

		.list {
			width: 690rpx;

			opacity: 1;
			background: #ffffff;
			border-radius: 20rpx;
			box-shadow: 0rpx 30rpx 18rpx -14rpx #e6ebf2;
			overflow: hidden;
			margin-top: 30rpx;


			.contains {
				width: 100%;
				padding: 20rpx;

				.text {
					width: 100%;
					line-height: 60rpx;

				}
			}


		}
	}

	.line {
		>view {
			width: 50%;
		}
	}

	.des {
		width: 100%;
		line-height: 40rpx;
		position: relative;
		text-align: justify;

		.blue {
			position: absolute;
			bottom: 0;
			right: 0;
		}
	}

	.btns {
		width: 100%;
		justify-content: flex-end;

		.btn1 {
			width: 184rpx;
			height: 64rpx;
			opacity: 1;
			background: #ffffff;
			border: 2rpx solid #dee2ee;
			border-radius: 44rpx;
		}

		.btn2 {
			width: 184rpx;
			height: 64rpx;
			opacity: 1;
			background: #fffefe;
			border: 2rpx solid #409eff;
			border-radius: 34rpx;
		}
	}
</style>

<template>
	<view class="content">
		<view class="nav bgwhite" id="nav">
			<view class="top bgwhite between-flex">
				<view class="search align-flex">
					<u-icon name="search" color="#666" size="34"></u-icon>
					<input class="ipt p-left20" type="text" v-model="keywords" @input="search" placeholder="搜索调研/项目" />
				</view>
				<view class="add colum-flex blue" @click="showPopup=true">
					<u-icon name="plus-circle" size="40"></u-icon>
					<view class=" f24 m-top10">申请</view>
				</view>
			</view>
			<u-tabs :list="nav" :is-scroll="false" bar-width="60" bar-height="4" :current="current" @change="change">
			</u-tabs>

		</view>
		<view :style="'height:'+navheight+'px;'"></view>
		<view class="lists" v-if="current==0">
			<view class="list" v-for="item,index in list" :key="index">

				<view class="contains between-flex">
					<view class="text">
						<view class="between-flex ">
							<view class="align-flex">
								<view class="gray m-right20">申请人</view><span
									class="textColor">{{item.createUserToName}}</span>
							</view>
							<view class="blue">
								{{item.state==1?'待审核':item.state==2?'审核通过':'审核失败'}}
							</view>
						</view>
						<view class="align-flex">
							<view class="gray m-right20">申请时间 </view><span class="textColor">{{item.createTime}}</span>
						</view>
						<view class="align-flex" v-if="item.reviewUser">
							<view class="gray m-right20">审核人 </view><span
								class="textColor">{{item.reviewUserToName}}</span>
						</view>
						<u-line margin="0 0 20rpx 0"></u-line>
						<view class="des">
							<span class="">
								{{item.remark}}

							</span>
							<!-- <span class="blue">查看完整内容</span> -->
						</view>

					</view>

				</view>

			</view>
		</view>
		<view class="lists" v-if="current==1">
			<view class="list" v-for="item,index in list" :key="index">

				<view class="contains between-flex">
					<view class="text">
						<view class="between-flex ">
							<view class="align-flex">
								<view class="gray m-right20">申请人</view><span
									class="textColor">{{item.createUserToName}}</span>
							</view>
							<view class="align-flex">
								<view class="gray m-right20">申请时间 </view><span
									class="textColor">{{item.createTime}}</span>
							</view>
						</view>
						<u-line margin="0 0 20rpx 0"></u-line>
						<view class="des">
							<span class="">
								{{item.remark}}

							</span>
						</view>
						<view class="align-flex btns m-top30">
							<view class="btn1 center-flex textColor m-right30" @click="reject(item)">驳回</view>
							<view class="btn2 center-flex blue" @click="accpet(item)">通过</view>
						</view>
					</view>

				</view>

			</view>
		</view>
		<view class="center-flex c999 f24" v-if="nomore">-没有更多了-</view>
		<view v-if="empty" style="position: fixed;top:40%;left:50%;transform: translateX(-50%);">
			<u-empty text="暂无列表"></u-empty>
		
		</view>
		<u-popup mode="bottom" v-model="showPopup" :closeable="true" borderRadius="20" :height="type==3?'90%':''">
			<change :itemCode="itemCode" @submit="showPopup=false;reset()"></change>
		</u-popup>
	</view>


</template>

<script>
	import change from '@/pagesProject/operation/change.vue'
	export default {
		components: {
			change
		},
		data() {
			return {
				navheight: 0,
				head: this.$head,
				nav: [{
					name: '我申请的',
					count: 0
				}, {
					name: '待我审核',
					count: 0
				}],
				current: 0,
				page: 1,
				showPopup: false,
				itemCode: 0,
				page: 1,
				list: [],
				nomore: false,
				empty: false,
				keywords: ''

			}
		},
		onLoad(e) {

			this.$nextTick(() => {
				let info = uni.createSelectorQuery().select("#nav");
				info.boundingClientRect((data) => {

					this.navheight = data.height

					console.log(this.navheight)
				}).exec()

			})
			this.itemCode = e.itemCode
			this.reset()
		},
		onReachBottom() {
			if (!this.nomore) {
				this.page++
				this.getlist()
			}
		},
		methods: {
			accpet(item) {
				
				uni.showModal({
					title: '确认通过审核吗？',
					success: (res) => {
						if (res.confirm) {
							this.$pop.ajaxPost('/busItemWorkReview/change/pass', {
								changeId: item.id
							}).then(res => {
								if (res.code == 0) {
									this.$msg('通过成功')
									this.reset()
								}
							})
						}
					}
				})
			},
			reject(item) {
				
				uni.showModal({
					title: '确认驳回审核吗？',
					success: (res) => {
						if (res.confirm) {
							this.$pop.ajaxPost('/busItemWorkReview/change/reject', {
								changeId: item.id
							}).then(res => {
								if (res.code == 0) {
									this.$msg('驳回成功')
									this.reset()
								}
							})
						}
					}
				})
			},
			reset() {
				this.$showloading()
				this.page = 1
				this.list = []
				this.nomore = false
				this.getlist()
				this.getRedInfo()
			},
			getlist() {
				var url=''
				if(this.current==0){
					url="/busItemWorkReview/change/myPage"
				}else if(this.current==1){
					url="/busItemWorkReview/change/myReview"
				}
				this.$pop.ajaxPost(url, {
					itemCode: this.itemCode,
					pageSize:10,
					pageNum:this.page
				}).then(res => {
					uni.hideLoading()
					var list = res.body.list

					this.list = this.list.concat(list)

					if (this.list.length == 0) {
						this.empty = true
					} else {
						this.empty = false
						if (list.length < 10) {
							this.nomore = true
						} else {
							this.nomore = false
						}
					}
					// console.log(this.list)
				})
			},
			getRedInfo() {
				this.$pop.ajaxPost('/busItemWorkReview/change/myPage', {
					itemCode: this.itemCode,
					pageNum:1,
					pageSize: 10
				}).then(res=>{
					this.nav[0].count=res.body.total
				})
				this.$pop.ajaxPost('/busItemWorkReview/change/myReview', {
					itemCode: this.itemCode,
					pageNum:1,
					pageSize: 10
				}).then(res=>{
					this.nav[1].count=res.body.total
				})
				
			},
			change(index) {
				this.current = index;
				this.reset()
			},

			search() {
				this.$u.debounce(this.reset, 500)

			},

		}
	}
</script>
